*&---------------------------------------------------------------------*
*& 包含               YBC_SWS_USER_MANAGE_CLS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       CLASS lcl_events DEFINITION
*----------------------------------------------------------------------*
* SALV Event Handler Definition                                        *
*----------------------------------------------------------------------*
CLASS GCL_EVENTS_HANDLER DEFINITION.
  PUBLIC SECTION.
    METHODS:
      ON_LINK_CLICK FOR EVENT LINK_CLICK  "Hotspot Handler
        OF CL_SALV_EVENTS_TABLE
        IMPORTING ROW COLUMN,

      ON_USER_COMMAND FOR EVENT ADDED_FUNCTION OF CL_SALV_EVENTS
        IMPORTING E_SALV_FUNCTION.
ENDCLASS.                    "lcl_events DEFINITION
*
*----------------------------------------------------------------------*
*       CLASS lcl_events IMPLEMENTATION
*----------------------------------------------------------------------*
*  SAL Event Handler Methods                                           *
*----------------------------------------------------------------------*
CLASS GCL_EVENTS_HANDLER IMPLEMENTATION.
  METHOD ON_LINK_CLICK.

  ENDMETHOD.                    "on_link_click

  METHOD ON_USER_COMMAND.
    DATA:
      LR_COLUMNS    TYPE REF TO CL_SALV_COLUMNS_TABLE.

    DATA:
      LS_SOLID      TYPE LVC_S_STBL,
      LV_TEXT       TYPE STRING,
      LS_MSG        TYPE BAPIRET2,
      LV_ANSWER     TYPE CHAR1,
      LV_ROW_COUNT  TYPE I,
      LS_RESULT     TYPE YBC_SWS_USER,
      LT_SELECT_D   TYPE STANDARD TABLE OF YBC_SWS_USER,
      LT_SELECT_ROW TYPE SALV_T_ROW,
      LS_SELECT_ROW TYPE I,
      LR_SELECTS    TYPE REF TO CL_SALV_SELECTIONS.

    CASE E_SALV_FUNCTION.
      WHEN 'ZIMPORT'.
        READ TABLE GT_USER_IMPORT TRANSPORTING NO FIELDS
          WITH KEY ICON = ICON_RED_LIGHT.
        IF SY-SUBRC = 0.
          MESSAGE TEXT-T04 TYPE 'E'.
        ELSE.

          LOOP AT GT_USER_IMPORT INTO GS_USER_IMPORT.
            CLEAR LS_RESULT.
            MOVE-CORRESPONDING GS_USER_IMPORT TO LS_RESULT.
            IF LS_RESULT-PASSWORD IS INITIAL.
              LS_RESULT-PASSWORD = GC_INITPWD.
            ENDIF.
            PERFORM FORM_ENPASSWORD USING LS_RESULT-PASSWORD CHANGING LS_RESULT-PASSWORD.
            LS_RESULT-PWD_INIT = 'X'.

            TRY .
                LS_RESULT-USERID = CL_SYSTEM_UUID=>CREATE_UUID_C32_STATIC( ).
              CATCH CX_UUID_ERROR.
                MESSAGE E009(YBC_SWS).
            ENDTRY.

            LS_RESULT-USERTY = '01'. "其它账号
            LS_RESULT-CRUSER = SY-UNAME.
            LS_RESULT-CRDATE = SY-DATUM.
            LS_RESULT-CRTIME = SY-UZEIT.

            APPEND LS_RESULT TO LT_SELECT_D.
          ENDLOOP.

          MODIFY YBC_SWS_USER FROM TABLE LT_SELECT_D.
          COMMIT WORK.

          MESSAGE TEXT-T05 TYPE 'S'.
        ENDIF.

      WHEN 'ZPWD_INT'.
        LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
        LT_SELECT_ROW = LR_SELECTS->GET_SELECTED_ROWS( ).
        LV_ROW_COUNT = LINES( LT_SELECT_ROW ).
        IF LV_ROW_COUNT = 0.
          MESSAGE S045(YBC_SWS) INTO LV_TEXT.
          MESSAGE LV_TEXT TYPE 'E'.

        ELSE.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
              TITLEBAR       = TEXT-T02
              TEXT_QUESTION  = TEXT-T02
            IMPORTING
              ANSWER         = LV_ANSWER
            EXCEPTIONS
              TEXT_NOT_FOUND = 1
              OTHERS         = 2.
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.

          IF LV_ANSWER = '1'.
            LOOP AT LT_SELECT_ROW INTO LS_SELECT_ROW.
              CLEAR LS_RESULT.
              READ TABLE GT_RESULT INTO LS_RESULT INDEX LS_SELECT_ROW.

              PERFORM FORM_ENPASSWORD USING GC_INITPWD CHANGING LS_RESULT-PASSWORD.

              LS_RESULT-PWD_INIT = 'X'.
              LS_RESULT-LAUSER = SY-UNAME.
              LS_RESULT-LADATE = SY-DATUM.
              LS_RESULT-LATIME = SY-UZEIT.
              APPEND LS_RESULT TO LT_SELECT_D.
            ENDLOOP.

            MODIFY YBC_SWS_USER FROM TABLE LT_SELECT_D.
            COMMIT WORK.

            PERFORM FORM_GET_DATA.
            LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
            LR_COLUMNS->SET_OPTIMIZE( 'X' ).
            GR_TABLE->REFRESH( ).

            MESSAGE S048.
          ENDIF.
        ENDIF.

      WHEN 'ZLOCK' OR 'ZUNLOCK'.
        LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
        LT_SELECT_ROW = LR_SELECTS->GET_SELECTED_ROWS( ).
        LV_ROW_COUNT = LINES( LT_SELECT_ROW ).
        IF LV_ROW_COUNT = 0.
          MESSAGE S045(YBC_SWS) INTO LV_TEXT.
          MESSAGE LV_TEXT TYPE 'E'.

        ELSE.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
              TITLEBAR       = TEXT-T01
              TEXT_QUESTION  = TEXT-T01
            IMPORTING
              ANSWER         = LV_ANSWER
            EXCEPTIONS
              TEXT_NOT_FOUND = 1
              OTHERS         = 2.
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.

          IF LV_ANSWER = '1'.
            LOOP AT LT_SELECT_ROW INTO LS_SELECT_ROW.
              CLEAR LS_RESULT.
              READ TABLE GT_RESULT INTO LS_RESULT INDEX LS_SELECT_ROW.
              IF SY-SUBRC = 0.
                IF E_SALV_FUNCTION = 'ZLOCK'.
                  LS_RESULT-INACTIVE = 'X'.
                ELSE.
                  CLEAR LS_RESULT-INACTIVE.
                ENDIF.
                LS_RESULT-LAUSER = SY-UNAME.
                LS_RESULT-LADATE = SY-DATUM.
                LS_RESULT-LATIME = SY-UZEIT.
                APPEND LS_RESULT TO LT_SELECT_D.
              ENDIF.
            ENDLOOP.

            MODIFY YBC_SWS_USER FROM TABLE LT_SELECT_D.
            COMMIT WORK.

            PERFORM FORM_GET_DATA.
            LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
            LR_COLUMNS->SET_OPTIMIZE( 'X' ).
            GR_TABLE->REFRESH( ).

            IF E_SALV_FUNCTION = 'ZLOCK'.
              MESSAGE S046.
            ELSE.
              MESSAGE S047.
            ENDIF.
          ENDIF.
        ENDIF.

      WHEN '&ZSETAG'.
        LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
        LT_SELECT_ROW = LR_SELECTS->GET_SELECTED_ROWS( ).

        LV_ROW_COUNT = LINES( LT_SELECT_ROW ).

        IF LV_ROW_COUNT <> 1.
          MESSAGE E020(YBC_SWS).
        ELSE.

          LOOP AT LT_SELECT_ROW INTO LS_SELECT_ROW.
            CLEAR GS_RESULT.
            READ TABLE GT_RESULT INTO GS_RESULT INDEX LS_SELECT_ROW.
            EXIT.
          ENDLOOP.

          IF GS_RESULT-INACTIVE IS NOT INITIAL.
            MESSAGE E056(YBC_SWS).

          ELSE.
            CALL SCREEN 9000 STARTING AT 20 3 ENDING AT 80 10.
          ENDIF.
        ENDIF.

      WHEN '&ZCLRAG'.
        LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
        LT_SELECT_ROW = LR_SELECTS->GET_SELECTED_ROWS( ).

        LV_ROW_COUNT = LINES( LT_SELECT_ROW ).

        IF LV_ROW_COUNT <> 1.
          MESSAGE E020(YBC_SWS).
        ELSE.

          LOOP AT LT_SELECT_ROW INTO LS_SELECT_ROW.
            CLEAR GS_RESULT.
            READ TABLE GT_RESULT INTO GS_RESULT INDEX LS_SELECT_ROW.
            EXIT.
          ENDLOOP.

          IF GS_RESULT-AG_USERID IS INITIAL.
            RETURN.
          ENDIF.

          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
              TITLEBAR       = TEXT-T06
              TEXT_QUESTION  = TEXT-T06
            IMPORTING
              ANSWER         = LV_ANSWER
            EXCEPTIONS
              TEXT_NOT_FOUND = 1
              OTHERS         = 2.
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.

          IF LV_ANSWER = '1'.

            CLEAR:
              GS_RESULT-AG_BEGDA,
              GS_RESULT-AG_ENDDA,
              GS_RESULT-AG_USERID,
              GS_RESULT-AG_TODO_COPY.


            GS_RESULT-LAUSER = SY-UNAME.
            GS_RESULT-LADATE = SY-DATUM.
            GS_RESULT-LATIME = SY-UZEIT.

            MODIFY YBC_SWS_USER FROM GS_RESULT.

            COMMIT WORK AND WAIT.

            PERFORM FORM_GET_DATA.
            LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
            LR_COLUMNS->SET_OPTIMIZE( 'X' ).
            LS_SOLID = 'XX'.
            GR_TABLE->REFRESH( EXPORTING S_STABLE = LS_SOLID ).

          ENDIF.
        ENDIF.
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.
ENDCLASS.                    "lcl_events IMPLEMENTATION

DATA: GR_EVENTS_HANDLER TYPE REF TO GCL_EVENTS_HANDLER.
